<!-- 专题页面 -->
<template>
  <div class="topic">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      loading-text="拼命加载中..."
      :immediate-check="true"
      @load="onLoad"
    >
      <!-- <van-cell v-for="item in list" :key="item" :title="item" /> -->
      <ul class="topic-container">
        <li class="item" v-for="item in list" :key="item.id" @click="goDetail(item.id)">
          <img class="img" :src="item.scene_pic_url" alt="">
          <div class="title">{{item.title}}</div>
          <div class="subtitle">{{item.subtitle}}</div>
          <div class="price">{{item.price_info}} 元起</div>
        </li>
      </ul>
    </van-list>
  </div>
</template>

<script>
import {
  listaction as listactionApi,

} from '@/api/topic'
export default {
  name: 'Topic',
  data() {
    return {
      page:1,//第几页数据
      list: [],
      loading: false, // 判断是否正在加载数据，true正在加载
      finished: false, // 所有数据是否加载完成，true就是所有数据加载完
    }
  },

  components: {},

  computed: {},

  created() {
   
  },

  mounted() {},

  methods: {
     onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求

      listactionApi({
        page:this.page
      })
      .then(res=>{
        // 加载状态结束
        this.loading = false;
        // console.log('res=>',res);
        this.list.push(...res.data) 
        this.page++
        if(this.page>res.total){
          // 数据全部加载完成
          this.finished = true
        }
      })
     
    },

    goDetail(id){
      this.$router.push({name:'topicDetail',query:{id}})
    }
 
  }
}
</script>
<style lang='scss' scoped>
.topic{
  margin-bottom: 50px;
  background-color: #f4f4f4;

  &-container{
    list-style: none;
    .item{
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      flex-wrap: wrap;
      margin-bottom: 10px;
      background-color: #fff;
      .img{
        width: 100%;
        height: auto;
      }
    }
  }
}
</style>